#include "../lvgl/examples/lv_examples.h"
#include <stdio.h>

static lv_obj_t * label ;
static lv_obj_t * label1 ;


static void event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);

    printf("调试按钮:code=%d...\n",code);
    
    if (code == LV_EVENT_CLICKED)
    {
        printf("按钮被点击！\n");
    }
    else if (code == LV_EVENT_LONG_PRESSED)
    {
        printf("长按事件..\n");
    }
}

static void event_handler1(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);

    printf("调试按钮:code=%d...\n",code);
    
    if (code == LV_EVENT_CLICKED)
    {
        printf("按钮被点击！\n");
    }
    else if (code == LV_EVENT_LONG_PRESSED)
    {
        printf("长按事件..\n");
    }
}

void myTest(void)
{
    
    // 创建按钮1
    static int Num = 0;
    lv_obj_t *btn1 = lv_btn_create(lv_scr_act());
    lv_obj_align(btn1, LV_ALIGN_LEFT_MID, 10, 20);
    lv_obj_set_size(btn1, 50, 200);
    
    // 修改这里：只注册需要的事件类型
    lv_obj_add_flag(btn1, LV_OBJ_FLAG_CLICKABLE);
    
    lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_CLICKED, &Num);
    lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_LONG_PRESSED, &Num);
    
    // 简化样式设置（先测试基本功能）
    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_radius(&style, 5);
    lv_style_set_bg_opa(&style, LV_OPA_COVER);
    lv_style_set_bg_color(&style, lv_palette_lighten(LV_PALETTE_LIGHT_GREEN, 1));
    lv_obj_add_style(btn1, &style, 0);
    
    //创建标签
    label = lv_label_create(btn1);
    lv_obj_center(label);
    lv_label_set_text_fmt(label, "prve", Num);


    // 创建按钮2
    static int Num1 = 0;
    lv_obj_t *btn2 = lv_btn_create(lv_scr_act());
    lv_obj_align(btn2, LV_ALIGN_RIGHT_MID, -10, 20);
    lv_obj_set_size(btn2, 50, 200);
    
    // 修改这里：只注册需要的事件类型
    lv_obj_add_flag(btn2, LV_OBJ_FLAG_CLICKABLE);
    
    lv_obj_add_event_cb(btn2, event_handler1, LV_EVENT_CLICKED, &Num1);
    lv_obj_add_event_cb(btn2, event_handler1, LV_EVENT_LONG_PRESSED, &Num1);
    
    // 简化样式设置（先测试基本功能）
    static lv_style_t style1;
    lv_style_init(&style1);
    lv_style_set_radius(&style1, 5);
    lv_style_set_bg_opa(&style1, LV_OPA_COVER);
    lv_style_set_bg_color(&style1, lv_palette_lighten(LV_PALETTE_LIGHT_GREEN, 1));
    lv_obj_add_style(btn2, &style1, 0);
    
    //创建标签
    label1 = lv_label_create(btn2);
    lv_obj_center(label1);
    lv_label_set_text_fmt(label1, "next", Num1);
}